package service;

import entity.*;
import model.*;
import util.ConverterTool;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class CarService implements ExcelInterface {

    public String importExcel(String path) {
        StringBuffer stringBuffer=new StringBuffer();
        List<CarDataModel> carList=ExeclService.importExcel(path,new CarDataModel());
        if(carList!=null){
            ArrayList<Litigation> litigationList=new ArrayList<>();
            ArrayList<LitigationBorrowerDetailed> litigationBorrowerDetaileds=new ArrayList<>();
            ArrayList<BusinessCar> businessCarList=new ArrayList<>();
            for (CarDataModel carDataModel : carList) {
                litigationList.add(ExeclService.buildLitigationObj(carDataModel));
                ArrayList<LitigationBorrowerDetailed> borrowerDetailedList = ExeclService.gainBorrower(carDataModel);
                borrowerDetailedList.forEach(item->{
                    litigationBorrowerDetaileds.add(item);
                });
                BusinessCar car=new BusinessCar();
                car.setId("UUID()");
                car.setCarBusinessId(carDataModel.getBusinessId());
                car.setOwnerName(carDataModel.getOwnerName());
                car.setLicensePlateNumber(carDataModel.getLicensePlateNumber());
                car.setCarBrand(carDataModel.getCarBrand());
                businessCarList.add(car);
            }
            stringBuffer.append(ExeclService.listToInsertSql(litigationList));
            stringBuffer.append(ExeclService.listToInsertSql(litigationBorrowerDetaileds));
            stringBuffer.append(ExeclService.listToInsertSql(businessCarList));
        }
        return stringBuffer.toString();
    }

    public int dataType() {
        return 2;
    }
}
